import { createSlice } from "@reduxjs/toolkit";

const userSlice=createSlice({ 
    name:"user",
    initialState:{
        // adminname:localStorage.getItem("adminname")||"",
        // token:localStorage.getItem("token")||"",
        // checkedkeys:[],
        // role:1,
        // loginState:true
        // 对象形式存储用户数据
        userInfo:JSON.parse(localStorage.getItem("userInfo")? localStorage.getItem("userInfo"): null),
    },
    reducers:{
        changeUserInfo(state, actions){
            state.userInfo=actions.payload
            localStorage.setItem("userInfo",JSON.stringify(actions.payload))

        },

    }
})

export const {changeUserInfo}=userSlice.actions
export default userSlice.reducer